import QtQuick 2.5
import QtQuick.Window 2.2
import QtQuick.Layouts 1.1
import "./Header"

Window {
    objectName: "mainWindow"
    visible: true
    width: 800
    height: 600
    signal selectMidItem(string content, string picpath)
    signal selectheader(bool isselect, int flag)

//    maximumWidth: 800
//    maximumHeight: 600
   // border.color: qsTr("black"); border.width: 2
  //  title: qsTr("Hello World")

//    MainForm {
//        anchors.fill: parent
//        mouseArea.onClicked: {
//            Qt.quit();
//            console.log("clicked the window")
//        }
    //    }

    //主界面
    Rectangle{
        id: mainview
//        signal selectheader(bool isselect, int flag)
//        signal selectMidItem(string content, string picpath)
        width: parent.width; height: parent.height
        // width: 800; height: 600
        anchors.fill: parent
        color: "white"

        Image {
            id: background
            source: "./images/mainui.png"
            anchors.centerIn: parent
        }
        //        ColumnLayout{
        //            id: layout
        //            anchors.fill: parent

        Header{
            id: header
            // width: parent.width; height: parent.height/9
            //                Layout.preferredWidth: parent.width
            //                Layout.preferredHeight: parent.height/9
            anchors.top: parent.top; anchors.left: parent.left; anchors.right: parent.right
            anchors.topMargin: 5; anchors.leftMargin: 2; anchors.rightMargin: 2
            onSelectone:
            {
                console.log(qsTr("send message to Middle --------main"))
                selectheader(isselect, flag)
            }

            //关闭窗口的信号
            onClosePage:
            {
                console.log("Header 向Tailer发出关闭选项卡的信号");
                tailer.oncloseItem()
                console.log("Header 向Middle发出关闭当前窗口的信号")
                middle.closePage()
            }
        }

        Tail{
            id: tailer
            anchors.bottom: parent.bottom; anchors.left: parent.left; anchors.right: parent.right
            anchors.bottomMargin: 5; anchors.leftMargin: 2; anchors.rightMargin: 2

            onMessage_Index:
            {
                console.log("Main收到了Index并顺手转发给了middle，实行middle.showPage(index)")
                middle.showPage(index)
            }
//            Connections{
//                target: middle
//                onTailItem:
//            }
        }

        Middle{
            id: middle
            width: parent.width
            anchors
            {
                top: header.bottom; bottom:tailer.top; left: header.left; right: header.right
                topMargin: 2; bottomMargin: 2
            }
            // onSelcetheader: showUI(isselect, flag)

            //            parent.onSelectheader:
            //            {
            //                console.log(qsTr("start show middle UI!"))
            //                middle.showUI(isselect, flag)
            //            }
            //            onHideMenu: {
            //                header.menu_pic = "../images/menu0.png"
            //            }
            onHideMenu: {
                console.log(qsTr("send \"hide menu\" message to Header\n\t\t\t===========Middle"))
                header.menuchange()
            }

            onToTail: {
                console.log(qsTr("发送”点击“消息给 tail 转发给 tailItem\n\t\t------Tail"))
                tailer.tailItem(content, picpath)
                //                tailer.itemContent = name
                //                tailer.itemPic = picpath

            }
        }

        TableWidget{

        }

        Connections{
            target: header
            onSelectone:
            {
                console.log(qsTr("get the message from header!\n Middle starts deal ---------main"))
                middle.showUI(isselect, flag)
            }
        }
    }
    //    }



}
